﻿#region using statements

using System;

using Microsoft.Xna.Framework;

using NGen;
using NGen.Managers.GUI;
using NGen.Managers.GameState;

using Nuclex.UserInterface;
using Nuclex.UserInterface.Controls.Desktop;

using XNAGameDemo.GameStates;

#endregion

namespace XNAGameDemo.GUI
{
	public class GUIElementMenuState : GUIElement
	{
		private readonly ButtonControl m_creditsButton = new ButtonControl();

		private readonly ButtonControl m_playButton = new ButtonControl();

		private readonly ButtonControl m_quitButton = new ButtonControl();

		private readonly ButtonControl m_settingsButton = new ButtonControl();

		private GUIElementSettings m_settingsElement;

		#region local methods

		/// <summary>
		/// 	Called whenever the next button is clicked
		/// </summary>
		protected void _PlayButtonClick(object p_sender, EventArgs p_e) {
			GameEngine.GetService<IManagerGameState>().ChangeState(new GameStatePlay1());
		}

		/// <summary>
		/// 	Called whenever the previous button is clicked
		/// </summary>
		protected void _SettingsButtonClick(object p_sender, EventArgs p_e) {
			m_settingsElement = new GUIElementSettings();
			GameEngine.GetService<IManagerGUI>().AddElement(m_settingsElement);
		}

		/// <summary>
		/// 	Called whenever the previous button is clicked
		/// </summary>
		protected void _CreditsButtonClick(object p_sender, EventArgs p_e) {
			GameEngine.GetService<IManagerGameState>().ChangeState(new GameStateCredits());
		}

		/// <summary>
		/// 	Called whenever the clicked button is clicked
		/// </summary>
		protected void _QuitButtonClick(object p_sender, EventArgs p_e) {
			GameEngine.Exit();
		}

		#endregion

		#region GUIElement implementation

		protected override void _Initialize() {
			m_playButton.Bounds = new UniRectangle(new UniScalar(0.5f, -75.0f), new UniScalar(0.3f, 0.0f), new UniScalar(150), new UniScalar(0.05f, 0.0f));
			m_playButton.Text = "Play";
			m_playButton.Pressed += _PlayButtonClick;
			_Children.Add(m_playButton);

			m_settingsButton.Bounds = new UniRectangle(new UniScalar(0.5f, -75.0f), new UniScalar(0.4f, 0.0f), new UniScalar(150), new UniScalar(0.05f, 0.0f));
			m_settingsButton.Text = "Settings";
			m_settingsButton.Pressed += _SettingsButtonClick;
			_Children.Add(m_settingsButton);

			m_creditsButton.Bounds = new UniRectangle(new UniScalar(0.5f, -75.0f), new UniScalar(0.5f, 0.0f), new UniScalar(150), new UniScalar(0.05f, 0.0f));
			m_creditsButton.Text = "Credits";
			m_creditsButton.Pressed += _CreditsButtonClick;
			_Children.Add(m_creditsButton);

			m_quitButton.Bounds = new UniRectangle(new UniScalar(0.5f, -75.0f), new UniScalar(0.6f, 0.0f), new UniScalar(150), new UniScalar(0.05f, 0.0f));
			m_quitButton.Text = "Quit";
			m_quitButton.Pressed += _QuitButtonClick;
			_Children.Add(m_quitButton);
		}

		protected override void Update(GameTime p_gameTime) {}

		protected override void _Cleanup() {
			GameEngine.GetService<IManagerGUI>().RemoveElement(m_settingsElement);
		}

		#endregion
	}
}